# coding=utf8
import datetime,time


def getIntegrationCycle(year,week):
    start = datetime.date(year, 1, 1)
    isfirst = start.weekday()

    if isfirst != 0:
        start += datetime.timedelta(7 - start.weekday())
    days = datetime.timedelta(weeks = int(week) - 1)
    end = start + days  # 每周的开始时间
    return {'year': end.year, 'week': end.strftime('%W'), 'start': end, 'end': end + datetime.timedelta(4)}

def getIntegrationCycleByDate(date):
    """
    传入date类型时间，返回{'week': '45', 'start': datetime.date(2017, 11, 6), 'end': datetime.date(2017, 11, 10), 'year': 2017}
    start 是周一  end是周五
    :param date:
    :return:
    """
    week = date.strftime('%W')
    return getIntegrationCycle(date.year,week)
if __name__ == "__main__":
    # now = datetime.datetime(2017,11,6)
    # print getIntegrationCycleByDate(now)
    # now = datetime.datetime.now()-datetime.timedelta(days=1)
    # print datetime.datetime(now.year,now.month,now.day,0,0,0)
    print datetime.datetime.now()
    time.sleep(10)
    print datetime.datetime.now()
    pass
